package com.example.config;
  
  
import com.example.service.i.FileStorageService;
import io.minio.MinioClient;  
import lombok.Data;  
import org.springframework.beans.factory.annotation.Autowired;  
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;  
import org.springframework.boot.context.properties.EnableConfigurationProperties;  
import org.springframework.context.annotation.Bean;  
import org.springframework.context.annotation.Configuration;  
  
  
@Data  
@Configuration  
@EnableConfigurationProperties({MinIOConfigProperties.class})  
//当引入FileStorageService接口时  
@ConditionalOnClass(FileStorageService.class)
public class MinIOConfig {  
  
    @Autowired  
    private MinIOConfigProperties minIOConfigProperties;  
  
    @Bean  
    public MinioClient buildMinioClient() {  
        return MinioClient  
                .builder()  
                .credentials(minIOConfigProperties.getAccessKey(), minIOConfigProperties.getSecretKey())  
                .endpoint(minIOConfigProperties.getEndpoint())  
                .build();  
    }  
}
